<!--广告页面-->
<template>
  <div class="user">
    <div class="handle">
      <el-button type="primary" @click="dialogVisibleStatic">添加</el-button>
    </div>
    <div class="handle">
      <el-table
        v-loading="isLoading"
        :data="bannerList"
        style="width: 100%"
      >
        <el-table-column
          label="标题"
          prop="title"
        />
        <el-table-column
          label="广告图"
        >
          <template slot-scope="scope">
            <el-image :src="scope.row.image" />
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          width="180"
        >
          <template slot-scope="scope">
            <el-button>删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-dialog
        title="提示"
        :visible.sync="dialogVisible"
        width="30%"
      >
        <span>这是一段信息</span>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="dialogVisibleStatic">添加</el-button>
          <el-button @click="dialogVisible = false">取 消</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>
<script>

import { getBannerList } from '@/api/banner'

export default {
  name: 'Index',
  data() {
    return {
      bannerList: {},
      isLoading: false,
      dialogVisible: false
    }
  },
  async created() {
    await this.getBanner()
  },
  methods: {
    async getBanner() {
      this.isLoading = true
      const res = await getBannerList()
      if (res.code !== 200) {
        this.$message({
          type: 'error',
          message: '数据获取失败',
          showClose: true,
          duration: 1500
        })
        this.isLoading = false
        return
      }
      this.bannerList = res.data
      this.isLoading = false
    },
    dialogVisibleStatic() {
      this.dialogVisible = !this.dialogVisible
    }
  }
}
</script>

<style scoped>
.user {
  padding: 10px;
  min-height: 100vh;
}
.handle{
  background-color: white;
  margin-top: 10px;
  padding: 30px 10px 10px 10px;
  border-radius: 10px;
  box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
}
.el-image{
  width: 80px;
}
</style>
